package com.yetong.domain.strategy.model.entity;

import com.yetong.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * 作者：叶童
 * 时间：2025/5/2
 * 策略实体
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StrategyEntity {
    //抽奖策略ID
    private Long strategyId;
    //抽奖策略描述
    private String strategyDesc;
    //规则模型，rule配置的模型同步到此表，便于使用
    private String ruleModels;

    public String[] ruleModels(){
       if(StringUtils.isBlank(ruleModels)){
           return null;
       }
       return ruleModels.split(Constants.SPLIT);
    }

    //获取是否存在权重值
    public String getRuleWeight(){
        String[] ruleModels = this.ruleModels();
        if (null == ruleModels) return null;
        for (String ruleModel : ruleModels) {
            if("rule_weight".equals(ruleModel)){
                return ruleModel;
            }
        }
        return null;
    }
}
